package com.api.shopapi.mapper;

import com.api.shopapi.entity.ServeclassServeGoodsRel;
import com.api.shopapi.entity.dto.ServeclassServeGoodsRelDTO;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;

import java.util.List;

@Mapper
@Repository
public interface ServeclassServeGoodsRelMapper {
    @Insert("insert into serveclass_serve_goods_rel " +
            "(" +
            "ServeclassServeGoodsRelCode, " +
            "ServeclassCode, " +
            "ServeclassName, " +
            "ServeCode, " +
            "ServeName, " +
            "GovernmentCode, " +
            "GoodsCode, " +
            "Sort" +
            ") " +
            "VALUES (#{serveclassServeGoodsRel.ServeclassServeGoodsRelCode} ," +
            "#{serveclassServeGoodsRel.ServeclassCode} ," +
            "#{serveclassServeGoodsRel.ServeclassName} ," +
            "#{serveclassServeGoodsRel.ServeCode} ," +
            "#{serveclassServeGoodsRel.ServeName} ," +
            "#{serveclassServeGoodsRel.GovernmentCode} ," +
            "#{serveclassServeGoodsRel.GoodsCode} ," +
            "#{serveclassServeGoodsRel.Sort} )")
    int insert(@Param("serveclassServeGoodsRel") ServeclassServeGoodsRel serveclassServeGoodsRel);

    @Update("update serveclass_serve_goods_rel set " +
            "ServeclassServeGoodsRelCode=#{serveclassServeGoodsRel.ServeclassServeGoodsRelCode} ," +
            "ServeclassCode=#{serveclassServeGoodsRel.ServeclassCode} ," +
            "ServeclassName=#{serveclassServeGoodsRel.ServeclassName} ," +
            "ServeCode=#{serveclassServeGoodsRel.ServeCode} ," +
            "ServeName=#{serveclassServeGoodsRel.ServeName} ," +
            "GovernmentCode=#{serveclassServeGoodsRel.GovernmentCode} ," +
            "GoodsCode=#{serveclassServeGoodsRel.GoodsCode} ," +
            "Sort=#{serveclassServeGoodsRel.Sort}  " +
            "where ServeclassServeGoodsRelCode=#{serveclassServeGoodsRel.ServeclassServeGoodsRelCode} and   "+
            "GovernmentCode=#{serveclassServeGoodsRel.GovernmentCode}")
    int update(@Param("serveclassServeGoodsRel") ServeclassServeGoodsRel serveclassServeGoodsRel);

    @Select("<script>" +
            "select * from serveclass_serve_goods_rel " +
            "where GovernmentCode=#{governmentCode}" +
            "<if test ='serveclassName !=\"\" '>" +
            " and ServeclassName like concat('%',#{serveclassName},'%')" +
            "</if>" +
            "<if test ='serveName !=\"\" '>" +
            " and ServeName like concat('%',#{serveName},'%')" +
            "</if>" +
            " order by Sort asc" +
            "</script>")
    List<ServeclassServeGoodsRelDTO> getPageList(@Param("serveclassName") String serveclassName,
                                                 @Param("serveName") String serveName,
                                                 @Param("governmentCode") String governmentCode );

    @Select("select * from serveclass_serve_goods_rel")
    List<ServeclassServeGoodsRel> getList();

    @Select("select  * from  serveclass_serve_goods_rel where GovernmentCode=#{governmentCode}")
    List<ServeclassServeGoodsRel> getByGovernmentCode(@Param("governmentCode") String governmentCode);

    @Select("select  * from  serveclass_serve_goods_rel where GovernmentCode=#{governmentCode} and ServeclassServeGoodsRelCode=#{serveclassServeGoodsRelCode}")
    ServeclassServeGoodsRel getByCodeAndGov(@Param("governmentCode") String governmentCode,@Param("serveclassServeGoodsRelCode") String serveclassServeGoodsRelCode);

    @Select("select  * from  serveclass_serve_goods_rel where GovernmentCode=#{governmentCode} and ServeclassCode=#{ServeclassCode} and ServeCode=#{ServeCode}")
    ServeclassServeGoodsRel getByGovAndServeCode(@Param("governmentCode") String governmentCode,@Param("ServeclassCode") String ServeclassCode,@Param("ServeCode") String ServeCode);

    @Select("select  * from  serveclass_serve_goods_rel where GoodsCode=#{goodsCode} limit 1")
    ServeclassServeGoodsRel getByGoodsCode(@Param("goodsCode") String goodsCode);

    @Delete("delete  from serveclass_serve_goods_rel where ServeclassServeGoodsRelCode=#{serveclassServeGoodsRelCode}")
    int delete(@Param("serveclassServeGoodsRelCode") String serveclassServeGoodsRelCode);
}
